<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="hyl.core.db.MyDB"%>
<%@ page import="hyl.My"%>
<%@ page
	import="java.util.*,java.sql.Connection,java.math.BigDecimal,com.alibaba.fastjson.JSON"%>
<%@ page import="java.util.UUID,java.io.PrintWriter"%>
<%
	String state = request.getParameter("state");
PrintWriter shuchu = response.getWriter();
	//detail.jsp
    if (state.equals("1")) {
		String goodsxid = request.getParameter("id");
		MyDB db2 = My.getDb1();
		String sql2 = "select a.oprice,b.yunfei from goodjiage a,goodinfo b,goodsx c where c.goodsxid=a.goodsxid and c.productid=b.productid and a.goodsxid=?";
		Object[] param2 = new Object[1];
		param2[0] = goodsxid;
		Map<String, Object> op = db2.queryMap(sql2, param2);
		//shuchu.println("{\"state\":"+op.get("oprice")+"}");
		shuchu.println(JSON.toJSONString(op));
		shuchu.close();
	}
  //detail.jsp
	if (state.equals("2")) {
        String userid=request.getParameter("userid");
        //System.out.println("25"+userid);
        String goodsxid=request.getParameter("goodsxid");
        int count=1;
       // System.out.println("27"+goodsxid);
        MyDB db2 = My.getDb1();
        Object[] params = new Object[3];
        params[0]=userid;
        params[1]=goodsxid;
        params[2]=count;
        String sql="insert into shopping (userid,goodsxid,count) values (?,?,?)";
        db2.executeUpdate(sql, params);
       // System.out.println("34"+"cg");
        shuchu.close();//添加到购物车
	}
    //shop.jsp
	if(state.equals("3")){
		String count=request.getParameter("count");
		String shopmxid=request.getParameter("shopmxid");
		 MyDB db2 = My.getDb1();
	        Object[] params = new Object[2];
	        params[0]=count;
	        params[1]=shopmxid;
	        String sql="update shopping set count=? where shopmxid=?";
	        db2.executeUpdate(sql, params);//修改购物车商品数量
	}
    //shop.jsp
	if(state.equals("4")){
		String count=request.getParameter("count");
		String shopmxid=request.getParameter("shopmxid");
		 MyDB db2 = My.getDb1();
	        Object[] params = new Object[2];
	        params[0]=count;
	        params[1]=shopmxid;
	        String sql="update shopping set count=? where shopmxid=?";
	        db2.executeUpdate(sql, params);//修改购物车商品数量
	}
    //assort.jsp
	if(state.equals("5")){
		String categoryID=request.getParameter("categoryID");
		    MyDB db = My.getDb1();
	        Object[] params = new Object[2];
	        params[0]=categoryID;
	        String sql = "select * from goodinfo where categoryID=?";
	        List<Map<String, Object>> list = db.queryList(sql, params);
	        shuchu.println(JSON.toJSONString(list));
			shuchu.close();//根据商品大类查询
	}
    //shop.jsp
	if(state.equals("6")){
		String shopmxid=request.getParameter("shopmxid");
		    MyDB db = My.getDb1();
	        Object[] params = new Object[1];
	        params[0]=shopmxid;
	        String sql = "delete from shopping where shopmxid=?";
	        db.executeUpdate(sql, params);//从购物车删除
	}
	//shop.jsp
	if(state.equals("7")){
		    String userid = (String) request.getSession().getAttribute("name");
		   
		    MyDB db = My.getDb1();
	        Object[] param = new Object[1];
	        param[0]=userid;
	        String sql="insert into dingdan (userid,ordertime,state) values (?,now(),1)";
	        int id=db.executeUpdate(sql, param);//添加到订单表
	        shuchu.println(id);
	        
	        //System.out.println("max="+id);
	        MyDB db1 = My.getDb1();
	        String sql1="select a.*,b.oprice from shopping a,goodjiage b where a.goodsxid=b.goodsxid and a.userid=? and a.count>0";
	        Object[] param1 = new Object[1];
	        param1[0]=userid;
	        List<Map<String, Object>> list = db1.queryList(sql1, param1);//查询购用户结算的所有商品
	        
	        MyDB db2 = My.getDb1();
	        List sqls1=new ArrayList();
	        List parms1=new ArrayList();
	        String sql2="insert into dingdanmx (orderid,goodsxid,ocount,oprice,pricetype,ddswift) values (?,?,?,?,'现金币',?)";
	        String ddswift="";
	        for (int l = 0; l < 10; l++) {
				String uuid = UUID.randomUUID().toString().replaceAll("-", "");
				ddswift=uuid;
			}
	        for(int i=0;i<list.size();i++){
	        	Map mp = (Map) list.get(i);
				int goodsxid=(int)mp.get("goodsxid");
				int count=(int)mp.get("count");
				BigDecimal oprice=(BigDecimal)mp.get("oprice");
				Object[] param2 = new Object[5];
				param2[0]=id;
			    param2[1]=goodsxid;
			    param2[2]=count;
			    param2[3]=oprice;
			    param2[4]=ddswift;			    
			    sqls1.add(sql2);
			    parms1.add(param2);
	        }  
	        db2.executeBatch(sqls1,parms1);//添加到订单明细
	}
	//detail.jsp
	if(state.equals("8")){
		  String userid=request.getParameter("userid");
	      String goodsxid=request.getParameter("goodsxid");
          String price=request.getParameter("oprice");
          BigDecimal oprice=new BigDecimal(price);
          String ddswift="";
          for (int l = 0; l < 10; l++) {
				String uuid = UUID.randomUUID().toString().replaceAll("-", "");
				ddswift=uuid;
			}
	      MyDB db = My.getDb1();
	      Object[] param = new Object[1];
	      param[0]=userid;
	      String sql="insert into dingdan (userid,ordertime,state) values (?,now(),1)";
	      int id=db.executeUpdate(sql, param);//添加到订单表   
	      shuchu.println(id);
	     
	      int count=1;  
	      MyDB db1 = My.getDb1();
	      Object[] param1 = new Object[5];
	      param1[0]=id; 
		  param1[1]=goodsxid;
		  param1[2]=count;
		  param1[3]=oprice;
		  param1[4]=ddswift;
	      String sql2="insert into dingdanmx (orderid,goodsxid,ocount,oprice,pricetype,ddswift) values (?,?,?,?,'现金币',?)";
	      db1.executeUpdate(sql2, param1);//添加到订单明细
	}
	//fukun.jsp
	if(state.equals("9")){
		 String liuyan=request.getParameter("liuyan");
		 String id=request.getParameter("id");
		 String dz=request.getParameter("dz");
		 MyDB db1 = My.getDb1();
	     Object[] param1 = new Object[3];
	     param1[0]=liuyan;
	     param1[1]=dz;
	     param1[2]=id;
	     String sql="update dingdan set liuyan=?,zhifutime=now(),addr=?, state=2 where orderid=?";
	     db1.executeUpdate(sql, param1);//确认支付
	}
%>
